package com.futurelight.recipes.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.futurelight.recipes.model.Result;
import com.futurelight.recipes.ui.fragment.DetailFragment;
import com.futurelight.recipes.ui.fragment.IngredientFragment;

public class DetailAdapter extends FragmentStateAdapter {

    private Result result;

    public DetailAdapter(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle) {
        super(fragmentManager, lifecycle);
    }

    /**
     * 两个fragment一个显示Detail信息,另一个显示材料信息
     * @param position
     * @return
     */
    @NonNull
    @Override
    public Fragment createFragment(int position) {
        if (position == 0) {
            return new DetailFragment(result);
        } else {
            return new IngredientFragment(result);
        }
    }

    @Override
    public int getItemCount() {
        return 2;
    }

    public void setResult(Result result){
        this.result = result;
    }
}
